{% extends "howto" %}

{% block main %}
                <h2 id="adding-storages">Adding storages</h2>
                <p>Storages are just specific tools.
                Just like them, their definition file can be included within their providing kit, or they can just provide a config file for a tool class taken from an external kit dependancy.</p>
                <p>They have to extend <strong>wakStorage</strong> class, which is provided by <strong>webappkit/storages</strong> kit.</p>
                <p>Their function is to retrieve object instances stored in files within the kit.</p>
                <p>Here we will get templates from our kit, using a storage class provided by <em>djtpl</em> template engine kit.</p>
                <p>Here's our kit's <em>wak.ini</em> :</p>
                <code>[load_kits]
; getting dependancies, including the storage class
0 = "djtpl"
; please note that djtpl kit itself require webappkit/storages

[tools]
; declaring storage, name = "class"
templates = "djtplstorage"</code>
                <p>And now we override some storage config in <em>templates.tool.ini</em> :</p>
                <code>; this is the templates storage config
search = "views/{{lang}}/{{id}}.{{type}}"
; here is the filename template for files search
[critera]
; the defaults values for search criteria
lang = "en"
type = "html"</code>
                </p>This settings indicate that template files will be stored within a <em>views/</em> folder within our kit,
                having languages subfolders, and that files are named by id.type.
                The default language is set to <em>en</em>, and default type to <em>html</em>.</p>
                <p>Now, let's get a template from our kit.
                First, we will change the language default value to <em>fr</em>.
                Then, we want the template having the <em>home</em> id.</p>
                <code>/**
 * changing a criteria's default value
 */
$kit->templates->setCriteria('lang','fr');
/**
 * getting a template
 * string criteria will be taken as 'id'
 * or you can provide an associative array for more criteria
 * missing criteria will be taken from current defaults
 * this will build a template instance from views/fr/home.html
 */
$tpl=$kit->templates->getItem('home');
/**
* rendering the template
*/
echo $tpl->render();</code>
{% endblock %}